﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace ReactiveCode.Statements
{
    class ProxyStatement: ReactiveStatement
    {
        IDisposable _enabledSubscription;

        ReactiveStatement _real;
        public ReactiveStatement Real
        {
            get { return _real; }
            set
            {
                if (_real == value)
                    return;

                if (_enabledSubscription != null)
                {
                    _enabledSubscription.Dispose();
                    _enabledSubscription = null;
                }

                _real = value;

                if (_real != null)
                    _enabledSubscription = BindEnabled(_real);
            }
        }

        public ProxyStatement(ReactiveStatement real = null)
        {
            Real = real;
        }
    }
}
